library(dplyr)
library(mapview)
library(sf)
library(spData)
library(osmdata)
library(rmapshaper)
library(ggplot2)
library(viridis)
#I added checks to troubleshoot, now they re commented
For this exercise, we will need first to import the file
swissBOUNDARIES3D_1_5_TLM_HOHEITSGEBIET.shp containing the
municipality boundary (do not use the file
swissBOUNDARIES3D_1_5_TLM_HOHEITSGRENZE.shp) and the
.csv file on housing price we used in the last exercise
session.
To avoid issues with this exercise, you should remove the
Z geometry (altitude of the point) of your municipality
boundary object using the function
st_zm(your municipality object, drop = TRUE). Do not forget
to save this as a new object.
The municipality boundary contains a detailed (hence precise) geometry but uses a lot of memory such that you might want to simplify it first.
In also contains several variables that might not be directly of use.
object.size()#IMPORTING
mun<- st_read("~/Desktop/spatialdata/assignement1/data/raw/Swiss boundary/swissBOUNDARIES3D_1_5_TLM_HOHEITSGEBIET.shp")
## Reading layer `swissBOUNDARIES3D_1_5_TLM_HOHEITSGEBIET' from data source
## `/Users/gualtieromarencoturi/Desktop/spatialdata/assignement1/data/raw/Swiss boundary/swissBOUNDARIES3D_1_5_TLM_HOHEITSGEBIET.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 2147 features and 23 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY, XYZ
## Bounding box: xmin: 2485410 ymin: 1075268 xmax: 2833858 ymax: 1295934
## z_range: zmin: 193.51 zmax: 4615.402
## Projected CRS: CH1903+ / LV95 + LN02 height
mun1 <- st_zm(mun, drop = TRUE)
sale<- st_read("/Users/gualtieromarencoturi/Desktop/spatialdata/assignement1/hp_small.csv", options = c("X_POSSIBLE_NAMES=longitude2", "Y_POSSIBLE_NAMES=latitude2"), stringsAsFactors=FALSE, crs = 4326)
## options: X_POSSIBLE_NAMES=longitude2 Y_POSSIBLE_NAMES=latitude2
## Reading layer `hp_small' from data source
## `/Users/gualtieromarencoturi/Desktop/spatialdata/assignement1/hp_small.csv'
## using driver `CSV'
## Simple feature collection with 10000 features and 16 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 5.99013 ymin: 45.8322 xmax: 10.4355 ymax: 47.7615
## Geodetic CRS: WGS 84
sale1<-st_zm(sale, drop = TRUE)
#MAP FOR VISUAL INSPECTION
sale1 %>% mapview(cex = 1, layer.name = "housing prices", legend = FALSE)